Printer.js ➔ Printer   A
last analyzed

Complexity

Conditions 1
Paths 64

Size

Total Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 64
dl 0
loc 67
rs 9.2815
c 1
b 0
f 0
nop 1

3 Functions

Rating   Name   Duplication   Size   Complexity  
A Printer.js ➔ ... ➔ this.violations 0 15 2
B Printer.js ➔ ... ➔ this.result 0 31 4
A Printer.js ➔ ... ➔ this.scenario 0 6 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var Slf4j = require('@ama-team/voxengine-sdk').Logger.Slf4j
2
var Validator = require('../Schema').Validator
3
4
/**
5
 * @param {LoggerOptions} [options]
6
 * @class
7
 */
8
function Printer (options) {
9
  var logger = Slf4j.factory(options, 'ama-team.vsf.api.printer')
10
11
  /**
12
   * @param {TScenario} scenario
13
   */
14
  this.scenario = function (scenario) {
15
    logger.info('Scenario information:')
16
    logger.info('ID: {}', scenario.id || null)
17
    logger.info('Version: {}', scenario.version || null)
18
    logger.info('Environment: {}', scenario.environment || null)
19
  }
20
21
  /**
22
   * @param {ViolationSet} violations
23
   */
24
  this.violations = function (violations) {
25
    var groups = violations.violations
26
    if (!Object.keys(groups).length) {
27
      logger.info('No violations have been found')
28
      return
29
    }
30
    logger.info('Found validation violations:')
31
    Object.keys(groups).forEach(function (path) {
32
      groups[path].forEach(function (v) {
33
        var severe = v.severity.weight > Validator.Severity.Minor
34
        var method = severe ? 'warn' : 'info'
35
        logger[method]('{}: {} ({})', path, v.message, v.severity.id)
36
      })
37
    })
38
  }
39
40
  /**
41
   * @param {TRunResult} result
42
   */
43
  this.result = function (result) {
44
    var method = result.status.successful ? 'notice' : 'error'
45
    logger[method]('Framework run has finished in {} ms with status {}',
46
      result.duration, result.status.id)
47
    if (result.value) {
48
      logger.info('Result value:', result.value)
49
    }
50
    var stages = result.stages
51
    Object.keys(stages).forEach(function (name) {
52
      var result = stages[name]
53
      if (!result) {
54
        logger.info('{} stage hasn\'t been run', name)
55
        return
56
      }
57
      if (result.status.successful) {
58
        logger.info('{} stage has successfully finished in {} ms:', name,
59
          result.duration, result.value)
60
      } else {
61
        logger.error('{} stage has failed in {} ms:', name, result.duration,
62
          result.value || result.error)
63
      }
64
    })
65
    if (stages.scenario) {
66
      logger.debug('Recapping scenario state history (limited to 100 entries):')
67
      stages.scenario.history.forEach(function (e) {
68
        logger.debug('{} -> {}: {} (hints: {}, value: {})', e.origin, e.target,
69
          e.status.id, e.hints, e.value)
70
      })
71
    }
72
    return result
73
  }
74
}
75
76
module.exports = {
77
  Printer: Printer
78
}
79